﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace The_Virginia_code.models
{
    public class MyEncoder
    {
        /// <summary>
        /// 密钥
        /// </summary>
        public string Key { get; set; }
        /// <summary>
        /// 密文
        /// </summary>
        public string Ciphertext { get; set; }
        /// <summary>
        /// 明文
        /// </summary>
        public string Plaintext { get; set; }
        /// 加密动作
        /// </summary>
        public void Encoder()
        {
            //加密过程
            for (int i = 0, j = 0; i < Plaintext.Length; i++, j++)
            {
                if (j % Key.Length == 0)
                    j = 0;
                Ciphertext += Convert.ToChar((Function(Plaintext[i]) + Function(Key[j])) % 26+'A');
            }
        }

        /// <summary>
        /// 返回指定字符在字母表中的序号，从0开始
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        private int Function(char ch)
        {
            return ch - 'A';
        }
    }
}
